package com.tarena.lbs.article.web.controller;

import com.tarena.lbs.article.web.service.ArticleService;
import com.tarena.lbs.base.protocol.exception.BusinessException;
import com.tarena.lbs.base.protocol.model.Result;
import com.tarena.lbs.base.protocol.pager.PageResult;
import com.tarena.lbs.pojo.content.param.ArticleContentParam;
import com.tarena.lbs.pojo.content.query.ArticleQuery;
import com.tarena.lbs.pojo.content.vo.ArticleActionPageResultVO;
import com.tarena.lbs.pojo.content.vo.ArticleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.HashSet;
import java.util.concurrent.ExecutionException;

@RestController
public class ArticleController {
    //手机端 后台 公用的分账分页列表查询
    @Autowired
    private ArticleService articleService;

    @GetMapping("/admin/content/article/list")
    public Result<PageResult<ArticleVO>> articlePage(ArticleQuery query)
            throws BusinessException, IOException {
        PageResult<ArticleVO> voPage = articleService.articlePage(query);
        return new Result(voPage);
    }

    //新增文章数据 后台 手机小程序
    @PostMapping("/admin/content/article/insert")
    public Result<Void> articleAdd(ArticleContentParam param)
            throws BusinessException {
        articleService.articleAdd(param);
        return Result.success();
    }


    //DAY11-PM 01 、查询手机定位范围内的文章标签集合
    @GetMapping("/admin/content/article/getArticleLabel")
    public Result<HashSet<String>> getArtitleLabels(ArticleQuery query)
            throws BusinessException, IOException {
        HashSet<String> labels=articleService.getArticleLabels(query);
        return new Result(labels);
    }
    @GetMapping("/admin/content/article/get")
    public Result<ArticleVO> articleDetail(Integer id)
            throws BusinessException{
        ArticleVO vo=articleService.getArticle(id);
        return new Result<>(vo);
    }

    @GetMapping("/admin/content/article/getBehaviorList")
    public Result<ArticleActionPageResultVO> actionList(ArticleQuery query)
            throws BusinessException, ExecutionException, InterruptedException {
        ArticleActionPageResultVO vo=articleService.actionList(query);
        return new Result<>(vo);
    }
}
